﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Windows;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Ink;
using System.Windows.Media.Imaging;
using System.Windows.Media;
namespace ocruit
{
      [Serializable]
        public class Letter : ISerializable
        {
          /// <summary>
          ///  
          /// </summary>
            List<string> sBase64 = new List<string>();
            int letterIndex;
           
          /// <summary>
          /// constructor
          /// </summary>
            public Letter()
            {
            }
          public Letter(int index)
            {
                for (int i = 0; i < index; i++)
                    sBase64.Add(null);
            }
            #region  serialize
            
            /// <summary>
          /// serialize object
          /// </summary>
          /// <param name="info"></param>
          /// <param name="context"></param>
            public Letter(SerializationInfo info, StreamingContext context)
            {
                this.sBase64 = (List<string>)info.GetValue("base64set", typeof(List<string>));
                this.letterIndex = (int)info.GetValue("letterIndex", typeof(int));

            }
            public void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                info.AddValue("base64set", this.sBase64);
                info.AddValue("letterIndex", this.letterIndex);
                Letter lt = new Letter();

            }
            #endregion
            #region get or set property
            
            public IEnumerable<string> getCode
            {
                get
                {
                    for (int i = 0; i < sBase64.Count; i++)

                        yield return sBase64[i];
                }
               
            }
          public List<string> getCodes
          {
              get
              {
                  return sBase64;
              }
              set
              {
                  sBase64 = value;
              }
          }
          public string getCodeAt(int index)
          {
              if (sBase64.Count != 0)
              {
                  if (index < sBase64.Count && index >= 0)
                      return sBase64[index];
                  else
                  {
                      if (index > 0)
                          return sBase64[sBase64.Count - 1];
                      else
                          return sBase64[0];
                  }
              }
              else return null;
          }
          public void setCode(int index , string value)
          {
              sBase64[index] = value;
          }

            #endregion
            #region list operation
          
          public void addInstance(string sb)
           {
               sBase64.Add(sb);
           }
          public void removeInstance(string sb)
            {
                sBase64.Remove(sb);
            }
          public void removeInstance(int index)
          {
              
              sBase64.RemoveAt(index);
          }
          public void RemoveAll()
          {
              sBase64.Clear();
          }
          #endregion
        }
  
}
